<?php
/**
 * Formulaire de mise a jour de news
 * @author Etienne AUDOUIN <etienne.audouin@ingesup.com>
 * @author Adrien MARIANELLI <adrien.marianelli@ingesup.com>
 * @version 1.0
 * @package view_news_update
 */

if (isset($idLetter) && $idLetter != 0)
    $selected = $idLetter;
else
    $selected = 'default';

echo form_fieldset('Select Newsletter');
echo form_open();

echo '<table id="table_newsletter">';
echo '<tr>';
echo '<th>Choose Newsletter</th>';
echo '<td>' . form_dropdown('select_newsletter', $titles, $selected) . '</td>';
echo '</tr>';
echo '</table>';

echo form_submit(null, 'Edit');
echo form_close();
echo form_fieldset_close();

if (isset($idLetter) && $idLetter != 0) {
    echo form_fieldset('Edit');
    echo form_open('webnews/doUpdateNewsLetter/' . $idLetter);

    echo '<div id="newsletterDisplay">';
    $data = array(
        'name' => 'title',
        'id' => 'editTitle',
        'value' => $newsletters[$idLetter]['title'],
    );
    echo form_input($data);
    echo '<br />';
    $data = array(
        'name' => 'content',
        'id' => 'editContent',
        'value' => $newsletters[$idLetter]['content'],
        'type' => 'text',
    );
    echo form_textarea($data);
    echo '<br />';
    $data = array(
        'name' => 'signature',
        'id' => 'editContent',
        'value' => $newsletters[$idLetter]['signature'],
    );
    echo form_input($data);
    echo '<br /><br />';

// mailinglists
    $listAttributes = array();
    $listAttributesSelected = array();
    foreach ($lists as $list) {
        $listAttributes[$list['id']] = $list['name'];
        foreach(explode(':', $newsletters[$idLetter]['id_mailinglists']) as $mailinglist) {
            if ($mailinglist == $list['id'])
                $listAttributes[$list['id']] .= ' (selected)';
        }
    }
    
    echo 'Mailing list *';
    echo form_multiselect('multi_mailingLists[]', $listAttributes);
    echo '</div>';

    echo form_submit(null, 'Valider');
    echo form_close();

    echo '<small>* Press <strong class="key">Maj</strong> or <strong class="key">Ctrl</strong> to select multiple contacts</small>';
    echo form_fieldset_close();
}
?>